﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Design;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;

namespace Dzzzr
{
	/// <summary>
	/// Add pictures to combo
	/// </summary>
	public class EntityTypeEditor : UITypeEditor
	{
		/// <summary>
		/// Image list
		/// </summary>
		ImageList imgEntityList = new ImageList();
		/// <summary>
		/// Constructor
		/// </summary>
		public EntityTypeEditor()
		{
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
			imgEntityList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgEntityList.ImageStream")));
			imgEntityList.TransparentColor = System.Drawing.Color.Transparent;
			imgEntityList.Images.SetKeyName(0, "Person.png");
			imgEntityList.Images.SetKeyName(1, "Car.png");
			imgEntityList.Images.SetKeyName(2, "Headquater.png");
			imgEntityList.Images.SetKeyName(3, "Faked.png");
			imgEntityList.Images.SetKeyName(4, "Team.png");
			imgEntityList.Images.SetKeyName(5, "User.png");
			imgEntityList.Images.SetKeyName(6, "Folder.png");
			imgEntityList.Images.SetKeyName(7, "FolderOpened.png");
		}

		/// <summary>
		/// Inform supported
		/// </summary>
		/// <param name="context"></param>
		/// <returns></returns>
		public override bool GetPaintValueSupported(ITypeDescriptorContext context)
		{
			return true;
		}

		/// <summary>
		/// get image for entity
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		protected Image ImageforEntity(Int32 entity)
		{
			switch (entity)
			{
				case EntityType.Person:
					return imgEntityList.Images[0];
				case EntityType.Car:
					return imgEntityList.Images[1];
				case EntityType.Headquater:
					return imgEntityList.Images[2];
				case EntityType.Faked:
					return imgEntityList.Images[3];
			}
			return null;
		}

		/// <summary>
		/// Draw icon
		/// </summary>
		/// <param name="e"></param>
		public override void PaintValue(PaintValueEventArgs e)
		{
			Image image = null;
			if (e.Value is EntityType)
				image = ImageforEntity(Convert.ToInt32((e.Value as EntityType).ID));
			if (image != null)
			{
				Rectangle destRect = e.Bounds;
				e.Graphics.DrawImage(image, destRect);
			}
		}
	}
}
